﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Laser_Controller : MonoBehaviour {
    public Sprite LaserOn;//激光打开图片
    public Sprite LaseOff;//激光关闭图片
    public float ChangeInterval = 0.5f;//图片切换间隔(ms)
    private SpriteRenderer ren;
    private bool isLaserOn = false;
	// Use this for initialization
	void Start () {
        ren = GetComponent<SpriteRenderer>();
        StartCoroutine("ChangeLaserSprite");
	}
	
	// Update is called once per frame
	void Update () {
	   
	}

    IEnumerator ChangeLaserSprite()
    {
        while (true)
        {
            yield return new WaitForSeconds(ChangeInterval);
            if (ren != null)
            {
                ren.sprite = isLaserOn ? LaserOn : LaseOff;
                isLaserOn = !isLaserOn;
            }
        }
    }
    
}
